﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace yield
{
    public class Hello
    {
        string[] s = { "Hello","World"};
        public IEnumerator<string> GetEnumerator()
        {
            //yield return "Hello";
            //yield return "World";//书上的代码

            foreach (string s1 in s)
            {
                yield return s1;
            }//我猜的代码
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Hello hello = new Hello();
            foreach (string s in hello)
            {
                Console.WriteLine(s);
            }
        }
    }
}
